package jdbc3;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Properties;

/**
 * @Auther:lele
 * @Date:2025/3/12
 */
public class jruidStudy {
    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        FileInputStream fileInputStream = new FileInputStream("src/jdbc3/druidJDBC.properties");
        properties.load(fileInputStream);

//        使用德鲁伊数据库连接池技术
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        Connection connection = dataSource.getConnection();
        System.out.println("connection = " + connection);

        String sql = "select * from grades";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();

        ArrayList<Brand> brands = new ArrayList<>();
        while(resultSet.next()){
            Brand brand = new Brand();
            brand.setGar_id(resultSet.getInt("gar_id"));
            brand.setStu_id(resultSet.getInt("stu_id"));
            brand.setGar_gra(resultSet.getInt("gra_gra"));
            brand.setCourse_id(resultSet.getInt("course_id"));

            brands.add(brand);

        }
        System.out.println("brands = " + brands);

    }
}
